// 封装本地存储操作模块
// 保存到本地存储
export const setItem = (key, value) => {
  if (typeof value === 'object' && value !== null) {
    value = JSON.stringify(value)
  }
  localStorage.setItem(key, value)
}

// 获取数据
export const getItem = data => {
  try {
    const value = JSON.parse(localStorage.getItem(data))
    return value
  } catch (error) {
    return data
  }
}

// 删除数据
export const removeItem = key => {
  if (typeof key !== 'string') {
    key = key.toString()
  }
  localStorage.removeItem(key)
}
